const myObj = {
	a: 1,
	b: [1, 2, {
			c: true
		},
		[3]
	],
	d: {
		e: 2,
		f: 3
	},
	g: null,
	like: [6, 8, 9]
}

function flatten(myObj) {
	const flatObj = {}
	let flag = null

	function formatKey(obj, keyName) {
		for (let key in obj) {
			if (typeof obj[key] === 'object' && obj[key] !== null) { //值为对象
				if (!keyName) {
					formatKey(obj[key], key)
				} else {
					if (Array.isArray(obj)) {
						formatKey(obj[key], `${keyName}[${key}]`)
					} else {
						formatKey(obj[key], `${keyName}.${key}`)
					}
				}
			} else { //值不为对象或者值为null
				if (!keyName) {
					flatObj[key] = obj[key]
				} else {
					if (Array.isArray(obj)) {
						flatObj[`${keyName}[${key}]`] = obj[key]
					} else {
						flatObj[`${keyName}.${key}`] = obj[key]
					}
				}
			}
		}
	}

	formatKey(myObj, flag)
	return flatObj
}
// flatten(myObj)
console.log(flatten(myObj))
